﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.CApDataFileReader
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using EngineeringInternalExtension;
using System;
using System.Collections;
using System.Xml;
using Tecnomatix.Engineering;


namespace DnProcessSimulateCommands;

internal class CApDataFileReader
{
  private string m_filePath;
  private XmlDocument m_document = new XmlDocument();
  private XmlElement m_rootElement;

  internal CApDataFileReader(string filePath) => this.m_filePath = filePath;

  internal bool Initialize()
  {
    bool flag = true;
    try
    {
      this.m_document.Load(this.m_filePath);
      this.m_rootElement = this.m_document.DocumentElement;
    }
    catch (Exception ex)
    {
      flag = false;
    }
    return flag;
  }

  internal void GetAllSteps(ref Hashtable stepsList)
  {
    XmlElement xmlElement1 = this.m_rootElement[CApDataFileDefinitions.StepsElement];
    for (int i = 0; i < xmlElement1.ChildNodes.Count; ++i)
    {
      XmlElement childNode = xmlElement1.ChildNodes[i] as XmlElement;
      string attribute1 = childNode.GetAttribute(CApDataFileDefinitions.IdAttribute);
      string attribute2 = childNode.GetAttribute(CApDataFileDefinitions.ViewIdAttribute);
      ITxObject objectFromIdString1 = TxEngineeringDataInternal.GetObjectFromIdString(attribute1);
      if (objectFromIdString1 != null)
      {
        CApC3DSnapshotNodeData dsnapshotNodeData = (CApC3DSnapshotNodeData) null;
        if (attribute2.Length != 0)
        {
          ITxObject objectFromIdString2 = TxEngineeringDataInternal.GetObjectFromIdString(attribute2);
          if (objectFromIdString2 != null)
            dsnapshotNodeData = new CApC3DSnapshotNodeData(objectFromIdString2 as TxSnapshot);
          else if (this.m_rootElement[CApDataFileDefinitions.ViewsElement].SelectSingleNode($"{CApDataFileDefinitions.ViewElement}[@{CApDataFileDefinitions.IdAttribute}='{attribute2}']") is XmlElement xmlElement2)
            dsnapshotNodeData = new CApC3DSnapshotNodeData(xmlElement2.GetAttribute(CApDataFileDefinitions.NameAttribute), xmlElement2.GetAttribute(CApDataFileDefinitions.DisplayNameAttribute));
        }
        stepsList.Add((object) objectFromIdString1.Id, (object) dsnapshotNodeData);
      }
    }
  }

  private bool DoesHaveAllSnapshots(bool defaultValue)
  {
    return !(this.m_rootElement[CApDataFileDefinitions.ViewsElement].GetAttribute(CApDataFileDefinitions.AllSnapshotsAttribute) == CApDataFileDefinitions.FalseValue);
  }

  private bool DoesHaveAnimation(bool defaultValue)
  {
    return !(this.m_rootElement[CApDataFileDefinitions.ViewsElement].GetAttribute(CApDataFileDefinitions.AnimationAttribute) == CApDataFileDefinitions.FalseValue);
  }

  private bool DoesCompressData(bool defaultValue)
  {
    return !(this.m_rootElement[CApDataFileDefinitions.ViewsElement].GetAttribute(CApDataFileDefinitions.CompressDataAttribute) == CApDataFileDefinitions.FalseValue);
  }

  private bool ShouldIncludePMIs(bool defaultValue)
  {
    return !(this.m_rootElement[CApDataFileDefinitions.ViewsElement].GetAttribute(CApDataFileDefinitions.IncludePMIsAttribute) == CApDataFileDefinitions.FalseValue);
  }

  private TxExportGraphicsAnimationFileFormatEx GetPdfMode(
    TxExportGraphicsAnimationFileFormatEx defaultMode)
  {
    TxExportGraphicsAnimationFileFormatEx pdfMode = defaultMode;
    string attribute = this.m_rootElement[CApDataFileDefinitions.ViewsElement].GetAttribute(CApDataFileDefinitions.PdfModeAttribute);
    if (attribute == CApDataFileDefinitions.PdfModeU3DAttributeValue)
      pdfMode = (TxExportGraphicsAnimationFileFormatEx) 0;
    else if (attribute == CApDataFileDefinitions.PdfModePRCAttributeValue)
      pdfMode = (TxExportGraphicsAnimationFileFormatEx) 1;
    return pdfMode;
  }

  private CApC3DDocumentationSettings.CApC3DIncludedObjectsMode GetIncludedObjectsMode(
    CApC3DDocumentationSettings.CApC3DIncludedObjectsMode defaultMode)
  {
    CApC3DDocumentationSettings.CApC3DIncludedObjectsMode includedObjectsMode = defaultMode;
    string attribute = this.m_rootElement[CApDataFileDefinitions.ViewsElement].GetAttribute(CApDataFileDefinitions.IncludedObjectsMode);
    if (attribute == CApDataFileDefinitions.OnlyDisplayedObjectsInSceneAttributeValue)
      includedObjectsMode = CApC3DDocumentationSettings.CApC3DIncludedObjectsMode.OnlyDisplayedObjectsInScene;
    else if (attribute == CApDataFileDefinitions.OnlyObjectsIncludedInSnapshotsAttributeValue)
      includedObjectsMode = CApC3DDocumentationSettings.CApC3DIncludedObjectsMode.OnlyObjectsIncludedInSnapshotsAndSimulation;
    else if (attribute == CApDataFileDefinitions.AllObjectsInSceneAttributeValue)
      includedObjectsMode = CApC3DDocumentationSettings.CApC3DIncludedObjectsMode.AllLoadedObjects;
    return includedObjectsMode;
  }

  internal CApC3DDocumentationSettings GetDocumentationSettings()
  {
    CApC3DDocumentationSettings documentationSettings = new CApC3DDocumentationSettings();
    documentationSettings.Compress3DDocuments = this.DoesCompressData(documentationSettings.Compress3DDocuments);
    documentationSettings.IncludePMIs = this.ShouldIncludePMIs(documentationSettings.IncludePMIs);
    documentationSettings.RecordAnimation = this.DoesHaveAnimation(documentationSettings.RecordAnimation);
    documentationSettings.StoreAllSnapshots = this.DoesHaveAllSnapshots(documentationSettings.StoreAllSnapshots);
    documentationSettings.IncludedObjectsMode = this.GetIncludedObjectsMode(documentationSettings.IncludedObjectsMode);
    documentationSettings.PdfMode = this.GetPdfMode(documentationSettings.PdfMode);
    return documentationSettings;
  }
}
